package com.zb.internetSpider.bulider;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;

import javax.annotation.Resource;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.tree.DefaultTreeCellRenderer;

import org.springframework.stereotype.Component;

import com.zb.internetSpider.gui.SpiderComponent;
import com.zb.internetSpider.gui.Theme;
import com.zb.internetSpider.gui.asiderPanel.AbstractSpiderAsiderPanel;
import com.zb.internetSpider.gui.footerBar.AbstractSpiderFooterBar;
import com.zb.internetSpider.gui.frame.AbstractSpiderFrame;
import com.zb.internetSpider.gui.frame.DefaultSpiderFrame;
import com.zb.internetSpider.gui.mainPanel.AbstractSpiderMainPanel;
import com.zb.internetSpider.gui.menuBar.AbstractSpiderMenuBar;
import com.zb.internetSpider.gui.splitPanel.AbstractSpiderSplitPane;
import com.zb.internetSpider.gui.tabsPanel.AbstractSpiderTabsPanel;
import com.zb.internetSpider.gui.tree.AbstractSpiderTree;
import com.zb.internetSpider.utils.CommonUtils;

/**
 * 
 * ClassName: DefaultSpiderGuiBuilder  
 * @Description: TODO 默认的应用构建器
 * @author zb
 * @date 2019年2月16日 下午1:56:24
 */
@Component
public class DefaultSpiderGuiBuilder extends AbstractSpiderBuilder {
		

	@Override
	public AbstractSpiderFrame frameBuilder(Theme theme, AbstractSpiderTabsPanel tabsPanel,
			AbstractSpiderMainPanel mainPanel, AbstractSpiderAsiderPanel asiderPanel, AbstractSpiderSplitPane splitPane,
			AbstractSpiderMenuBar menuBar, AbstractSpiderFooterBar footerBar, AbstractSpiderTree spiderTree) {
		// TODO Auto-generated method stub
		this.spiderFrame = new DefaultSpiderFrame();
		boolean success = false;
		if(theme.getTabsFont() != null) {
			tabsPanel.setFont(theme.getTabsFont(), null);
			tabsPanel.setTabLayoutPolicy(theme.getTabsLayoutPolicy());
		}
				
		mainPanel.setLayout(new BorderLayout());
		mainPanel.add(tabsPanel, BorderLayout.NORTH);
		mainPanel.setBackground(theme.getMainBackGroundColor());
		
		spiderTree.setFont(theme.getMenuTreeFont(), theme.getMenuTreeFontColor());
		spiderTree.setSize(220,600);
//		spiderTree.setAlignmentY(6);
//		spiderTree.setAlignmentX(16);
//		spiderTree.
		spiderTree.setClosedIcon(theme.getMenuTreeCloseIcon())
		.setOpenIcon(theme.getMenuTreeOpenIcon()).setLeafIcon(theme.getMenuTreeLeafIcon());
//		spiderTree.setBackgroundNonSelectionColor(theme.getAsiderBackGroundColor());
		spiderTree.setBackGroundColor(theme.getAsiderBackGroundColor());
		spiderTree.setRootVisible(false);
		/**
		 * 去掉树上节点之间的连线
		 */
		spiderTree.putClientProperty("JTree.lineStyle", "None");
			
		asiderPanel.setBackground(theme.getAsiderBackGroundColor());	
		asiderPanel.setMenu(spiderTree);
		
		splitPane.setDividerSize(2);
		splitPane.setDividerLocation(214);
		splitPane.addSpiderContainer(asiderPanel, mainPanel);
		
		menuBar.setFont(theme.getMenuBarFont(), theme.getMenuBarFontColor());
		menuBar.setBackground(theme.getMenuBarBackGroundColor());
		menuBar.setSize(CommonUtils.getScreenSize().width, 56);
		
		footerBar.setBackground(theme.getFooterBackGroundColor());
		footerBar.setFont(theme.getFooterFont(), theme.getFooterFontColor());	
		footerBar.setSize(CommonUtils.getScreenSize().width, theme.getFooterHeight());	
		
		spiderFrame.setTheme(theme);		
		spiderFrame.setLayout(new BorderLayout());
		spiderFrame.addSpiderContainer(menuBar, footerBar, splitPane);
		
		this.spiderFrame.setTitle(theme.getTitle());
		this.spiderFrame.setFont(theme.getCommonFont(), theme.getFrameFontColor());
		this.spiderFrame.setIconImage(theme.getLogo());		
		this.spiderFrame.setLocationRelativeTo(null); // 居中对齐
		this.spiderFrame.setSize(CommonUtils.getHalfScreenSize());		
		this.spiderFrame.setBackground(Color.WHITE);
		this.spiderFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		return this.spiderFrame;
	}

	@Override
	public boolean frameBuilder(Theme theme, SpiderComponent... components) {
		// TODO Auto-generated method stub
		return false;
	}

}
